using HKB.Common;
using System;
using System.Data;
namespace HKB.Web
{
	public class CurrPageLinks
	{
		private static CurrPageLinks _instance = null;
		public static CurrPageLinks instance
		{
			get
			{
				if (CurrPageLinks._instance == null)
				{
					CurrPageLinks._instance = new CurrPageLinks();
				}
				return CurrPageLinks._instance;
			}
		}
		public string CurrPageLink(int page, int pageSize, int pCount, string Strmenber)
		{
			return this.CurrPageLink(page, pageSize, pCount, Strmenber, "?page");
		}
		public string CurrPageLink(int page, int pageSize, int pCount, string Strmenber, string Url)
		{
			string text = "";
			int num = page - 1;
			int num2 = page + 1;
			int num3 = (int)Math.Ceiling((double)pCount / (double)pageSize);
			object obj = text;
			text = string.Concat(new object[]
			{
				obj,
				"共：",
				pCount,
				Strmenber,
				" "
			});
			if (num < 1)
			{
				text += "首页 | ";
				text += "上一页 | ";
			}
			else
			{
				text = text + "<a href=\"" + Url + "=1\">首页</a> | ";
				obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"<a href=\"",
					Url,
					"=",
					num,
					"\">上一页</a> | "
				});
			}
			if (num2 > num3)
			{
				text += "<span title=\"下一页\">&nbsp;下一页&nbsp;</span>";
				text += "<span title=\"末页\">末页&nbsp;</span>";
			}
			else
			{
				obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"<span title=\"下一页\">&nbsp;<a href=\"",
					Url,
					"=",
					num2,
					"\">下一页</a>&nbsp;</span>"
				});
				obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"<span title=\"末页\"><a href=\"",
					Url,
					"=",
					num3,
					"\">末页</a>&nbsp;</span>"
				});
			}
			obj = text;
			return string.Concat(new object[]
			{
				obj,
				"页次： ",
				page,
				" / ",
				num3
			});
		}
		public string CurrPageLinkStr(int page, int pageSize, int pCount, string Strmenber, string Url)
		{
			string text = "";
			int num = page - 1;
			int num2 = page + 1;
			int num3 = (int)Math.Ceiling((double)pCount / (double)pageSize);
			if (num3 > 1)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"共：",
					pCount,
					Strmenber,
					" "
				});
				if (num < 1)
				{
					text += "首页 | ";
					text += "上一页 | ";
				}
				else
				{
					text = text + "<a href=\"" + Url + "=1\">首页</a> | ";
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<a href=\"",
						Url,
						"=",
						num,
						"\">上一页</a> | "
					});
				}
				if (num2 > num3)
				{
					text += "<span title=\"下一页\">&nbsp;下一页&nbsp;</span>";
					text += "<span title=\"末页\">末页&nbsp;</span>";
				}
				else
				{
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<span title=\"下一页\">&nbsp;<a href=\"",
						Url,
						"=",
						num2,
						"\">下一页</a>&nbsp;</span>"
					});
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<span title=\"末页\"><a href=\"",
						Url,
						"=",
						num3,
						"\">末页</a>&nbsp;</span>"
					});
				}
				obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"页次： ",
					page,
					" / ",
					num3
				});
			}
			return text;
		}
		public string CurrPageLinkStr(int page, int pageSize, int pCount, string Strmenber, string Url, bool isShowDownList)
		{
			string text = "";
			int num = page - 1;
			int num2 = page + 1;
			int num3 = (int)Math.Ceiling((double)pCount / (double)pageSize);
			if (num3 > 1)
			{
				object obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"共：",
					pCount,
					Strmenber,
					" "
				});
				if (num < 1)
				{
					text += "首页 | ";
					text += "上一页 | ";
				}
				else
				{
					text = text + "<a href=\"" + Url + "=1\">首页</a> | ";
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<a href=\"",
						Url,
						"=",
						num,
						"\">上一页</a> | "
					});
				}
				if (num2 > num3)
				{
					text += "<span title=\"下一页\">&nbsp;下一页&nbsp;</span>";
					text += "<span title=\"末页\">末页&nbsp;</span>";
				}
				else
				{
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<span title=\"下一页\">&nbsp;<a href=\"",
						Url,
						"=",
						num2,
						"\">下一页</a>&nbsp;</span>"
					});
					obj = text;
					text = string.Concat(new object[]
					{
						obj,
						"<span title=\"末页\"><a href=\"",
						Url,
						"=",
						num3,
						"\">末页</a>&nbsp;</span>"
					});
				}
				obj = text;
				text = string.Concat(new object[]
				{
					obj,
					"页次： ",
					page,
					" / ",
					num3
				});
				if (isShowDownList)
				{
					string text2 = "&nbsp;&nbsp;跳转到：";
					string text3 = text2;
					text2 = string.Concat(new string[]
					{
						text3,
						Language.GetMemberMsg("to", new string[0]),
						"<select name='page' onChange=\"javascript:location.href='",
						Url,
						"='+this.options[this.selectedIndex].value;\">"
					});
					for (int i = 1; i <= num3; i++)
					{
						if (i >= 1000)
						{
							break;
						}
						obj = text2;
						text2 = string.Concat(new object[]
						{
							obj,
							"<option value='",
							i,
							"'"
						});
						if (i == page)
						{
							text2 += " selected ";
						}
						obj = text2;
						text2 = string.Concat(new object[]
						{
							obj,
							">",
							Language.GetMemberMsg("Article", new string[0]),
							i,
							Language.GetMemberMsg("Paged", new string[0]),
							"</option>"
						});
					}
					text2 += "</select>";
					text += text2;
				}
			}
			return text;
		}
		public DataTable GetPagedTable(DataTable dt, int PageIndex, int PageSize)
		{
			DataTable result;
			if (PageIndex == 0)
			{
				result = dt;
			}
			else
			{
				DataTable dataTable = dt.Copy();
				dataTable.Clear();
				int num = (PageIndex - 1) * PageSize;
				int num2 = PageIndex * PageSize;
				if (num >= dt.Rows.Count)
				{
					result = dataTable;
				}
				else
				{
					if (num2 > dt.Rows.Count)
					{
						num2 = dt.Rows.Count;
					}
					for (int i = num; i <= num2 - 1; i++)
					{
						DataRow dataRow = dataTable.NewRow();
						DataRow dataRow2 = dt.Rows[i];
						foreach (DataColumn dataColumn in dt.Columns)
						{
							dataRow[dataColumn.ColumnName] = dataRow2[dataColumn.ColumnName];
						}
						dataTable.Rows.Add(dataRow);
					}
					result = dataTable;
				}
			}
			return result;
		}
	}
}
